package com.quick.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.quick.common.annotation.Log;
import com.quick.common.core.controller.BaseController;
import com.quick.common.core.domain.AjaxResult;
import com.quick.common.enums.BusinessType;
import com.quick.system.domain.DutyRecord;
import com.quick.system.service.IDutyRecordService;
import com.quick.common.utils.poi.ExcelUtil;
import com.quick.common.core.page.TableDataInfo;

/**
 * 值班记录Controller
 * 
 * @author quick
 * @date 2025-01-04
 */
@RestController
@RequestMapping("/server/record")
public class DutyRecordController extends BaseController
{
    @Autowired
    private IDutyRecordService dutyRecordService;

    /**
     * 查询值班记录列表
     */
    @PreAuthorize("@ss.hasPermi('server:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(DutyRecord dutyRecord)
    {
        startPage();
        List<DutyRecord> list = dutyRecordService.selectDutyRecordList(dutyRecord);
        return getDataTable(list);
    }

    /**
     * 导出值班记录列表
     */
    @PreAuthorize("@ss.hasPermi('server:record:export')")
    @Log(title = "值班记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DutyRecord dutyRecord)
    {
        List<DutyRecord> list = dutyRecordService.selectDutyRecordList(dutyRecord);
        ExcelUtil<DutyRecord> util = new ExcelUtil<DutyRecord>(DutyRecord.class);
        util.exportExcel(response, list, "值班记录数据");
    }

    /**
     * 获取值班记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('server:record:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(dutyRecordService.selectDutyRecordById(id));
    }

    /**
     * 新增值班记录
     */
    @PreAuthorize("@ss.hasPermi('server:record:add')")
    @Log(title = "值班记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DutyRecord dutyRecord)
    {
        return toAjax(dutyRecordService.insertDutyRecord(dutyRecord));
    }

    /**
     * 修改值班记录
     */
    @PreAuthorize("@ss.hasPermi('server:record:edit')")
    @Log(title = "值班记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DutyRecord dutyRecord)
    {
        return toAjax(dutyRecordService.updateDutyRecord(dutyRecord));
    }

    /**
     * 删除值班记录
     */
    @PreAuthorize("@ss.hasPermi('server:record:remove')")
    @Log(title = "值班记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(dutyRecordService.deleteDutyRecordByIds(ids));
    }
}
